package com.itheima.app.controller.smsController;

import com.itheima.app.manager.smsManager.SmsHomeAdvertiseManager;
import com.itheima.app.manager.smsManager.SmsHomeRecommendSubjectManager;
import com.itheima.commons.PageBeanResult;
import com.itheima.commons.PageResult;
import com.itheima.commons.R;
import com.itheima.domain.db.sms.SmsHomeAdvertise;
import com.itheima.domain.db.sms.SmsHomeRecommendSubject;
import com.itheima.service.smsService.SmsHomeAdvertiseService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class SmsHomeController {

    //TODO:江云天 -专题推荐

    @Autowired
    private SmsHomeRecommendSubjectManager smsHomeRecommendSubjectManager;

    //分页查询推荐
    @GetMapping("/home/recommendSubject/list")
    public R listBy(Integer pageNum, Integer pageSize, String subjectName, Integer recommendStatus) {

        PageBeanResult pageBean = smsHomeRecommendSubjectManager.listBy(pageNum, pageSize, subjectName, recommendStatus);

        return R.ok(pageBean);
    }

    //添加首页推荐专题
    @PostMapping("/home/recommendSubject/create")
    public R create(@RequestBody SmsHomeRecommendSubject smsHomeRecommendSubject) {

        smsHomeRecommendSubjectManager.create(smsHomeRecommendSubject);

        return R.ok(null);
    }

    //批量删除专题推荐推荐
    @PostMapping("/home/recommendSubject/delete")
    public R deleteids(Integer[] ids) {

        smsHomeRecommendSubjectManager.deleteids(ids);

        return R.ok(null);
    }

    //批量修改推荐状态
    @PostMapping("/home/recommendSubject/update/recommendStatus")
    public R update(Integer[] ids, Integer recommendStatus) {

        smsHomeRecommendSubjectManager.update(ids, recommendStatus);

        return R.ok(null);
    }

    //修改推荐排序
    @PostMapping("/home/recommendSubject/update/sort/{id}")
    public R updateBySort(@PathVariable Integer id, Integer sort) {

        smsHomeRecommendSubjectManager.updateBySort(id, sort);

        return R.ok(null);
    }
    @Autowired
    SmsHomeAdvertiseManager smsHomeAdvertiseManager;

    //添加广告
    @PostMapping("/home/advertise/create")
    public R save(@RequestBody SmsHomeAdvertise smsHomeAdvertise){
        return smsHomeAdvertiseManager.save(smsHomeAdvertise);
    }

    //删除广告
    @PostMapping("/home/advertise/delete")
    public R delete(@RequestParam("ids")List<Long> ids){
        return smsHomeAdvertiseManager.delete(ids);
    }

    //分页查询
    @GetMapping("/home/advertise/list")
    public R findByPage(@RequestParam(value = "endTime",required = false)String endTime,
                        @RequestParam(value = "name",required = false)String name,
                        @RequestParam(value = "pageNum",required = false) Integer pageNum,
                        @RequestParam(value = "pageSize",required = false ) Integer pageSize,
                        @RequestParam(value = "type",required = false)Integer type){

        return smsHomeAdvertiseManager.findByPage(endTime,name,pageNum,pageSize,type);
    }

    //修改上下线状态
    @PostMapping("/home/advertise/update/status/{id}")
    public R update(@PathVariable Long id,@RequestParam("status")Integer status){
        return smsHomeAdvertiseManager.update(id,status);
    }

    //修改广告
    @PostMapping("/home/advertise/update/{id}")
    public R updateById(@PathVariable Long id,@RequestBody SmsHomeAdvertise smsHomeAdvertise){
        return smsHomeAdvertiseManager.updateById(id, smsHomeAdvertise);
    }

    //获取广告详情
    @GetMapping("/home/advertise/{id}")
    public R getAdvertiseById(@PathVariable Long id){
        return smsHomeAdvertiseManager.getAdvertiseById(id);
    }
}
